<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/pjax@0.2.8/pjax.js"></script> 

  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"linzhuangrong.gitee.io","root":"/blog/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Lvm存储服务">
<meta property="og:type" content="article">
<meta property="og:title" content="Lvm管理">
<meta property="og:url" content="https://linzhuangrong.gitee.io/blog/2019/11/15/LVM/index.html">
<meta property="og:site_name" content="Rong的博客">
<meta property="og:description" content="Lvm存储服务">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-11-14T16:00:00.000Z">
<meta property="article:modified_time" content="2022-03-15T15:52:59.710Z">
<meta property="article:author" content="林壮荣">
<meta property="article:tag" content="linux">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://linzhuangrong.gitee.io/blog/2019/11/15/LVM/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Lvm管理 | Rong的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Rong的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://linzhuangrong.gitee.io/blog/2019/11/15/LVM/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="林壮荣">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Rong的博客">
    </span>
      <header class="post-header">
	  
        <h1 class="post-title" itemprop="name headline">
          Lvm管理
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-11-15 00:00:00" itemprop="dateCreated datePublished" datetime="2019-11-15T00:00:00+08:00">2019-11-15</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-03-15 23:52:59" itemprop="dateModified" datetime="2022-03-15T23:52:59+08:00">2022-03-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Linux/%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86/" itemprop="url" rel="index"><span itemprop="name">存储管理</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
            <div class="post-description">Lvm存储服务</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="Lvm管理磁盘空间"><a href="#Lvm管理磁盘空间" class="headerlink" title="Lvm管理磁盘空间"></a>Lvm管理磁盘空间</h2><p>逻辑卷管理LVM（Logical Volume Manager）是Linux系统的一种管理硬盘分区机制，具有动态管理硬盘的能力。本文介绍了如何通过LVM在多块云盘上创建一个逻辑卷，适用于Linux实例。</p>
<h3 id="通过LVM创建逻辑卷"><a href="#通过LVM创建逻辑卷" class="headerlink" title="通过LVM创建逻辑卷"></a>通过LVM创建逻辑卷</h3><h4 id="创建物理卷"><a href="#创建物理卷" class="headerlink" title="创建物理卷"></a>创建物理卷</h4><p>【<strong>查看磁盘信息</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">vda    253:0    0  100G  0 disk</span><br><span class="line">└─vda1 253:1    0  100G  0 part /</span><br><span class="line">vdb    253:16   0  200G  0 disk</span><br><span class="line">vdc    253:32   0  200G  0 disk</span><br></pre></td></tr></table></figure>
<p>【<strong>安装lvm2</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y lvm2</span><br></pre></td></tr></table></figure>
<p>【<strong>分区</strong>】</p>
<ul>
<li><p><strong>mbr分区</strong></p>
<p>1、查看磁盘</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">fdisk -l</span><br><span class="line"></span><br><span class="line">Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors</span><br><span class="line">Units = sectors of 1 * 512 = 512 bytes</span><br><span class="line">Sector size (logical/physical): 512 bytes / 512 bytes</span><br><span class="line">I/O size (minimum/optimal): 512 bytes / 512 bytes</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors</span><br><span class="line">Units = sectors of 1 * 512 = 512 bytes</span><br><span class="line">Sector size (logical/physical): 512 bytes / 512 bytes</span><br><span class="line">I/O size (minimum/optimal): 512 bytes / 512 bytes</span><br><span class="line">Disk label <span class="built_in">type</span>: dos</span><br><span class="line">Disk identifier: 0x000cd8ec</span><br><span class="line"></span><br><span class="line">Device Boot      Start         End      Blocks   Id  System</span><br><span class="line">/dev/sda1   *        2048    41943039    20970496   83  Linux</span><br><span class="line"></span><br><span class="line">Disk /dev/sdc: 536.9 GB, 536870912000 bytes, 1048576000 sectors</span><br><span class="line">Units = sectors of 1 * 512 = 512 bytes</span><br><span class="line">Sector size (logical/physical): 512 bytes / 512 bytes</span><br><span class="line">I/O size (minimum/optimal): 512 bytes / 512 bytes</span><br></pre></td></tr></table></figure>

<p>2、分区</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">fdisk /dev/vdb</span><br><span class="line"></span><br><span class="line">Welcome to fdisk (util-linux 2.23.2).</span><br><span class="line"></span><br><span class="line">Changes will remain <span class="keyword">in</span> memory only, until you decide to write them.</span><br><span class="line">Be careful before using the write <span class="built_in">command</span>.</span><br><span class="line"></span><br><span class="line">Device does not contain a recognized partition table</span><br><span class="line">Building a new DOS disklabel with disk identifier 0xe80f8142.</span><br><span class="line"></span><br><span class="line">Command (m <span class="keyword">for</span> <span class="built_in">help</span>): n</span><br><span class="line">Partition <span class="built_in">type</span>:</span><br><span class="line">  p   primary (0 primary, 0 extended, 4 free)</span><br><span class="line">  e   extended</span><br><span class="line">Select (default p): p</span><br><span class="line">Partition number (1-4, default 1): 1</span><br><span class="line">First sector (2048-1048575999, default 2048): </span><br><span class="line">Using default value 2048</span><br><span class="line">Last sector, +sectors or +size&#123;K,M,G&#125; (2048-1048575999, default 1048575999): </span><br><span class="line">Using default value 1048575999</span><br><span class="line">Partition 1 of <span class="built_in">type</span> Linux and of size 500 GiB is <span class="built_in">set</span></span><br><span class="line"></span><br><span class="line">Command (m <span class="keyword">for</span> <span class="built_in">help</span>): t</span><br><span class="line">Selected partition 1</span><br><span class="line">Hex code (<span class="built_in">type</span> L to list all codes): 8e</span><br><span class="line">Changed <span class="built_in">type</span> of partition <span class="string">&#x27;Linux&#x27;</span> to <span class="string">&#x27;Linux LVM&#x27;</span></span><br><span class="line"></span><br><span class="line">Command (m <span class="keyword">for</span> <span class="built_in">help</span>): w</span><br><span class="line">The partition table has been altered!</span><br><span class="line"></span><br><span class="line">Calling ioctl() to re-read partition table.</span><br><span class="line">Syncing disks.</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>gpt分区</strong></p>
<p>1、分区</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">parted /dev/sdb</span><br><span class="line">mklabel gpt</span><br><span class="line">unit TB <span class="comment"># 设置单位为TB</span></span><br><span class="line">mkpart primary 0 3  设置3TB的分区</span><br><span class="line">mkpart primary 0 1396MB </span><br><span class="line">mkpart primary 0 -1</span><br><span class="line">toggle 1 lvm  <span class="comment"># 打上lvm标签</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<p>【<strong>创建物理卷pv</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 新建物理卷</span></span><br><span class="line">pvcreate /dev/vdb /dev/vdc</span><br><span class="line">  Physical volume <span class="string">&quot;/dev/vdb&quot;</span> successfully created.</span><br><span class="line">  Physical volume <span class="string">&quot;/dev/vdc&quot;</span> successfully created.</span><br><span class="line"><span class="comment"># 扩容物理卷</span></span><br><span class="line">pvresize /dev/vdb</span><br><span class="line">Physical volume <span class="string">&quot;/dev/vdb&quot;</span> changed</span><br><span class="line">  1 physical volume(s) resized or updated / 0 physical volume(s) not resized</span><br></pre></td></tr></table></figure>

<p>【<strong>查看pv信息</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">lvmdiskscan</span><br><span class="line">  /dev/vda1 [    &lt;100.00 GiB]</span><br><span class="line">  /dev/vdb  [     200.00 GiB] LVM physical volume</span><br><span class="line">  /dev/vdc  [     200.00 GiB] LVM physical volume</span><br><span class="line">  0 disks</span><br><span class="line">  1 partition</span><br><span class="line">  2 LVM physical volume whole disks</span><br><span class="line">  0 LVM physical volumes</span><br></pre></td></tr></table></figure>

<h4 id="创建卷组"><a href="#创建卷组" class="headerlink" title="创建卷组"></a>创建卷组</h4><p>【<strong>创建卷组VG</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">vgcreate mongo_rs /dev/vdb /dev/vdc</span><br><span class="line">  Volume group <span class="string">&quot;mongo_rs&quot;</span> successfully created</span><br></pre></td></tr></table></figure>
<p>【<strong>查看卷组信息</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vgs</span><br><span class="line">VG       <span class="comment">#PV #LV #SN Attr   VSize   VFree</span></span><br><span class="line">  mongo_rs   2   0   0 wz--n- 399.99g 399.99g</span><br></pre></td></tr></table></figure>

<h4 id="创建逻辑卷"><a href="#创建逻辑卷" class="headerlink" title="创建逻辑卷"></a>创建逻辑卷</h4><p>【<strong>创建逻辑卷LV</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 创建lv</span></span><br><span class="line">lvcreate -L 350g -n mongo_rs_lv mongo_rs</span><br><span class="line">Logical volume <span class="string">&quot;mongo_rs_lv&quot;</span> created</span><br><span class="line"><span class="comment"># 扩容lv</span></span><br><span class="line">lvextend -L +21.99G /dev/lvm_test/lvm_test_lv</span><br><span class="line">  Rounding size to boundary between physical extents: 21.99 GiB.</span><br><span class="line">  Size of logical volume lvm_test/lvm_test_lv changed from 18.00 GiB (4608 extents) to 39.99 GiB (10238 extents).</span><br><span class="line">  Logical volume lvm_test/lvm_test_lv successfully resized. </span><br></pre></td></tr></table></figure>
<p>【<strong>查看逻辑卷</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">lvdisplay</span><br><span class="line"></span><br><span class="line">  --- Logical volume ---</span><br><span class="line">  LV Path                /dev/mongo_rs/mongo_rs_lv</span><br><span class="line">  LV Name                mongo_rs_lv</span><br><span class="line">  VG Name                mongo_rs</span><br><span class="line">  LV UUID                4VLpZ3-YTkN-cq65-nE03-O4GB-W4wK-eYLq0N</span><br><span class="line">  LV Write Access        <span class="built_in">read</span>/write</span><br><span class="line">  LV Creation host, time mongdb-01, 2022-01-20 14:57:28 +0800</span><br><span class="line">  LV Status              available</span><br><span class="line">  <span class="comment"># open                 0</span></span><br><span class="line">  LV Size                350.00 GiB</span><br><span class="line">  Current LE             89600</span><br><span class="line">  Segments               2</span><br><span class="line">  Allocation             inherit</span><br><span class="line">  Read ahead sectors     auto</span><br><span class="line">  - currently <span class="built_in">set</span> to     8192</span><br><span class="line">  Block device           252:0</span><br></pre></td></tr></table></figure>

<h4 id="创建并挂载文件系统"><a href="#创建并挂载文件系统" class="headerlink" title="创建并挂载文件系统"></a>创建并挂载文件系统</h4><p>【<strong>创建ext4文件系统</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 格式化文件系统</span></span><br><span class="line">mkfs.ext4 /dev/mongo_rs/mongo_rs_lv</span><br><span class="line"></span><br><span class="line">mke2fs 1.42.9 (28-Dec-2013)</span><br><span class="line">文件系统标签=</span><br><span class="line">OS <span class="built_in">type</span>: Linux</span><br><span class="line">块大小=4096 (<span class="built_in">log</span>=2)</span><br><span class="line">分块大小=4096 (<span class="built_in">log</span>=2)</span><br><span class="line">Stride=0 blocks, Stripe width=0 blocks</span><br><span class="line">22937600 inodes, 91750400 blocks</span><br><span class="line">4587520 blocks (5.00%) reserved <span class="keyword">for</span> the super user</span><br><span class="line">第一个数据块=0</span><br><span class="line">Maximum filesystem blocks=2239758336</span><br><span class="line">2800 block groups</span><br><span class="line">32768 blocks per group, 32768 fragments per group</span><br><span class="line">8192 inodes per group</span><br><span class="line">Superblock backups stored on blocks:</span><br><span class="line">	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,</span><br><span class="line">	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968</span><br><span class="line"></span><br><span class="line">Allocating group tables: 完成</span><br><span class="line">正在写入inode表: 完成</span><br><span class="line">Creating journal (32768 blocks): 完成</span><br><span class="line">Writing superblocks and filesystem accounting information: 完成</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新文件系统</span></span><br><span class="line"><span class="comment">## ext4</span></span><br><span class="line">resize2fs /dev/lvm_test/lvm_test_lv</span><br><span class="line">resize2fs 1.42.9 (28-Dec-2013)</span><br><span class="line">Filesystem at /dev/lvm_test/lvm_test_lv is mounted on /data; on-line resizing required</span><br><span class="line">old_desc_blocks = 3, new_desc_blocks = 5</span><br><span class="line">The filesystem on /dev/lvm_test/lvm_test_lv is now 10483712 blocks long.</span><br><span class="line"><span class="comment">## xfs</span></span><br><span class="line">xfs_growfs /dev/lvm_test/lvm_test_lv</span><br></pre></td></tr></table></figure>

<p>【<strong>创建挂载点</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir /data</span><br></pre></td></tr></table></figure>

<p>【<strong>挂载文件系统</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mount /dev/mongo_rs/mongo_rs_lv /data</span><br></pre></td></tr></table></figure>

<p>【<strong>查看逻辑卷挂载信息</strong>】</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">df -TPh</span><br><span class="line"></span><br><span class="line">文件系统                         类型      容量  已用  可用 已用% 挂载点</span><br><span class="line">/dev/vda1                        ext4       99G  1.9G   93G    2% /</span><br><span class="line">devtmpfs                         devtmpfs  7.5G     0  7.5G    0% /dev</span><br><span class="line">tmpfs                            tmpfs     7.6G     0  7.6G    0% /dev/shm</span><br><span class="line">tmpfs                            tmpfs     7.6G  544K  7.6G    1% /run</span><br><span class="line">tmpfs                            tmpfs     7.6G     0  7.6G    0% /sys/fs/cgroup</span><br><span class="line">tmpfs                            tmpfs     1.6G     0  1.6G    0% /run/user/0</span><br><span class="line">/dev/mapper/mongo_rs-mongo_rs_lv ext4      345G   69M  327G    1% /data</span><br></pre></td></tr></table></figure>
<p>【<strong>添加开机启动</strong>】</p>
<ul>
<li><p>查看uuid</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">blkid</span><br><span class="line">/dev/vda1: UUID=<span class="string">&quot;1114fe9e-2309-4580-b183-d778e6d97397&quot;</span> TYPE=<span class="string">&quot;ext4&quot;</span></span><br><span class="line">/dev/vdb: UUID=<span class="string">&quot;ev6YG0-PurR-p4hP-1mNM-ZDpr-36eE-zndFzA&quot;</span> TYPE=<span class="string">&quot;LVM2_member&quot;</span></span><br><span class="line">/dev/mapper/mongo_rs-mongo_rs_lv: UUID=<span class="string">&quot;0d567c75-6fbc-41e0-98ef-df78bcd74433&quot;</span> TYPE=<span class="string">&quot;ext4&quot;</span></span><br><span class="line">/dev/vdc: UUID=<span class="string">&quot;UjWQY7-oSHb-pcmS-wc39-M9uI-Zbqd-YEITMf&quot;</span> TYPE=<span class="string">&quot;LVM2_member&quot;</span></span><br></pre></td></tr></table></figure></li>
<li><p>添加到开机启动</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">vim &#x2F;etc&#x2F;fstab</span><br><span class="line">UUID&#x3D;0d567c75-6fbc-41e0-98ef-df78bcd74433 &#x2F;data ext4 defaults 0 0</span><br><span class="line">&#96;&#96;&#96; </span><br><span class="line"></span><br><span class="line">### 通过LVM管理逻辑卷</span><br><span class="line">#### LVM扩容</span><br><span class="line">- 扩容pv卷</span><br><span class="line"></span><br><span class="line">  **扩容pv**</span><br><span class="line">  &#96;&#96;&#96;bash</span><br><span class="line">  pvresize &#x2F;dev&#x2F;vdb</span><br></pre></td></tr></table></figure>
<p><strong>扩容逻辑卷</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">lvextend -L +50G /dev/mongo_rs/mongo_rs_lv</span><br></pre></td></tr></table></figure>
<p><strong>扩容文件系统</strong></p>
<ul>
<li>ext4文件系统<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">resize2fs /dev/mongo_rs/mongo_rs_lv </span><br></pre></td></tr></table></figure></li>
<li>xfs文件系统<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xfs_growfs /dev/mongo_rs/mongo_rs_lv </span><br></pre></td></tr></table></figure></li>
</ul>
<p><strong>查看文件系统</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">df -TPH</span><br></pre></td></tr></table></figure>
</li>
<li><p>新增pv卷</p>
</li>
</ul>
<p><strong>增加pv</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pvcreate /dev/vdf</span><br></pre></td></tr></table></figure>

<p><strong>扩展vg</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vgextend  mongo_rs /dev/vdf</span><br></pre></td></tr></table></figure>

<p><strong>扩容逻辑卷</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">lvextend -L +50G /dev/mongo_rs/mongo_rs_lv</span><br></pre></td></tr></table></figure>

<p><strong>扩容文件系统</strong></p>
<ul>
<li>ext4文件系统<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">resize2fs /dev/mongo_rs/mongo_rs_lv </span><br></pre></td></tr></table></figure></li>
<li>xfs文件系统<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xfs_growfs /dev/mongo_rs/mongo_rs_lv </span><br></pre></td></tr></table></figure></li>
</ul>
<p>  <strong>查看文件系统</strong><br>  <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">df -TPH</span><br></pre></td></tr></table></figure></p>
<h4 id="LVM缩容"><a href="#LVM缩容" class="headerlink" title="LVM缩容"></a>LVM缩容</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 查看挂载</span></span><br><span class="line">mount</span><br><span class="line"><span class="meta">#</span><span class="bash"> 卸载lv</span></span><br><span class="line">umount /dev/centos-home</span><br><span class="line">e2fsck -f /dev/centos-home</span><br><span class="line"><span class="meta">#</span><span class="bash"> 缩减逻辑边界</span></span><br><span class="line">resize2fs /dev/centos-home  5G</span><br><span class="line"><span class="meta">#</span><span class="bash"> 缩减物理边界</span></span><br><span class="line">lvchange  -a n /dev/centos-home</span><br><span class="line">lvreduce -L 5G /dev/centos-home</span><br><span class="line">lvchange  -a y /dev/centos-home</span><br><span class="line">e2fsck  -f /dev/centos-home</span><br><span class="line"><span class="meta">#</span><span class="bash"> 挂载</span></span><br><span class="line">mount /dev/centos-home /home</span><br></pre></td></tr></table></figure>

    </div>

    
    
    
 
    <div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/blog/2019/11/15/LVM/">Lvm管理</a></p>
  <p><span>文章作者:</span><a href="/" title="访问  的个人博客"></a></p>
  <p><span>发布时间:</span>2019年11月15日 - 00:11</p>
  <p><span>最后更新:</span>2022年03月15日 - 23:03</p>
  <p><span>原始链接:</span><a href="/blog/2019/11/15/LVM/" title="Lvm管理">https://linzhuangrong.gitee.io/blog/2019/11/15/LVM/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://linzhuangrong.gitee.io/blog/2019/11/15/LVM/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
    });
    });  
</script>


      
    </div>

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/linux/" rel="tag"># linux</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2019/09/15/redis-cluster5%20-%202/" rel="prev" title="Redis支持三种集群方案">
      <i class="fa fa-chevron-left"></i> Redis支持三种集群方案
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2021/08/15/Linux%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E5%AE%9E%E6%88%98/" rel="next" title="Linux性能优化实战 笔记">
      Linux性能优化实战 笔记 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Lvm%E7%AE%A1%E7%90%86%E7%A3%81%E7%9B%98%E7%A9%BA%E9%97%B4"><span class="nav-number">1.</span> <span class="nav-text">Lvm管理磁盘空间</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%9A%E8%BF%87LVM%E5%88%9B%E5%BB%BA%E9%80%BB%E8%BE%91%E5%8D%B7"><span class="nav-number">1.1.</span> <span class="nav-text">通过LVM创建逻辑卷</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E7%89%A9%E7%90%86%E5%8D%B7"><span class="nav-number">1.1.1.</span> <span class="nav-text">创建物理卷</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%8D%B7%E7%BB%84"><span class="nav-number">1.1.2.</span> <span class="nav-text">创建卷组</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E9%80%BB%E8%BE%91%E5%8D%B7"><span class="nav-number">1.1.3.</span> <span class="nav-text">创建逻辑卷</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%B9%B6%E6%8C%82%E8%BD%BD%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F"><span class="nav-number">1.1.4.</span> <span class="nav-text">创建并挂载文件系统</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#LVM%E7%BC%A9%E5%AE%B9"><span class="nav-number">1.1.5.</span> <span class="nav-text">LVM缩容</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->
    
           <div>
            <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=144301&auto=1&height=66"></iframe>
           </div>
   
      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">林壮荣</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">20</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">林壮荣</span>
</div>
<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共31.2k字</span>
</div>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="powered-by">
  <i class="fa fa-user-md"></i>
  <span id="busuanzi_container_site_pv">
    本站访问量:<span id="busuanzi_value_site_pv"></span>次
  </span>
  <span class="post-meta-divider">|</span>
  <span id="busuanzi_container_site_uv">
    本站总访客量：<span id="busuanzi_value_site_uv"></span>人
  </span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  




  
<script src="/blog/js/local-search.js"></script>













  

  

</body>
</html>
